﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TimeClock
{
    public partial class FloatWindow : Form
    {
        //鼠标是否拖动标志
        private bool isDragging = false;
        //鼠标按下时的位置
        private Point downPosition;
        //鼠标按下时的窗体位置
        private Point lastFormPosition;
        public FloatWindow()
        {
            InitializeComponent();
        }

        private void Time_label_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //置标志为true
                isDragging = true;
                //保存当前鼠标坐标
                downPosition = Cursor.Position;
                //保存当前窗体坐标
                lastFormPosition = this.Location;
            }
        }

        private void Time_label_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDragging)
            {
                // 计算鼠标移动的偏移量
                int moveX = Cursor.Position.X - downPosition.X;
                int moveY = Cursor.Position.Y - downPosition.Y;

                // 更新窗体的位置
                this.Location = new Point(lastFormPosition.X + moveX, lastFormPosition.Y + moveY);
            }
        }

        private void Time_label_MouseUp(object sender, MouseEventArgs e)
        {
            //如果是鼠标左键松开，则修改标志为false
            if (e.Button == MouseButtons.Left)
            {
                isDragging = false;
            }
        }

        public void update_timer_text(string text)
        {
            this.Time_label.Text = text;
        }
    }
}
